package org.example.test;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.example.bean.Book;
import org.example.bean.Category;
import org.example.bean.User;
import org.example.service.BookService;
import org.example.service.CategoryService;
import org.example.service.UserService;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

@SpringBootTest
@Slf4j
public class App {
    @Resource
    private BookService bookservice;
    @Resource
    private UserService userservice;
    @Resource
    private CategoryService categoryservice;
    //查Book
    @Test
    public void findBook() {
        List<Book> list = bookservice.list();
        list.forEach(e->{
            log.info("e:{}",e);
        });
    }
    @Test
    public void insertBook(){
        Book book = new Book();
        book.setName("死亡万花筒");
        book.setAuthor("西子绪");
        book.setPublisher("出版社");
        book.setDescription(".....");
        book.setPrice("49.9");
        book.setCategoryId("1521453234854564569");
        bookservice.save(book);
    }
    @Test
    public void updateBook(){
        Book book = new Book();
        book.setPrice("79");
        book.setId("1811932173723947011");
        bookservice.updateById(book);
    }
    @Test
    public void deleteBook(){
        bookservice.removeById("1811932173723947011");
    }
    //查User
    @Test
    public void findUser(){
        List<User> userList= userservice.list();
        userList.forEach(u->{
            log.info("u:{}",u);
        });
    }
    @Test
    public void insertUser(){
        User user = new User();
        user.setUsername("hhh");
        user.setPassword("123");
        user.setPhone("15486452865");
        user.setEmail("48512@qq.com");
        user.setAddress("xx省xx");
        userservice.save(user);
    }
    @Test
    public void updateUser(){
        User user = new User();
        user.setAddress("陕西省西安市");
        user.setId("1833780340620636162");
        userservice.updateById(user);
    }
    @Test
    public void deleteUser(){
        userservice.removeById("1837332418467061761");
    }
    //查Category
    @Test
    public void findCategory(){
        List<Category> categories = categoryservice.list();
        categories.forEach(c->{
            log.info("c:{}",c);
        });
    }
    @Test
    public void insertCategory(){
        Category category = new Category();
        category.setName("小说11");
        category.setSort(13);
        categoryservice.save(category);
    }
    @Test
    public void updateCategory(){
        Category category = new Category();
        category.setName("hshshhh");
        category.setId("1833790578329387009");
        categoryservice.updateById(category);
    }
    @Test
    public void deleteCategory(){
        categoryservice.removeById("1833790578329387009");
    }
}
